/** 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.free.i.virtual.machine.hal.devicealias;

import it.free.i.virtual.machine.hal.devicealias.command.DeviceAliasCommand;
import it.free.i.virtual.machine.hal.devicealias.command.DeviceAliasPortCommand;

import javax.management.Notification;

import org.apache.log4j.Logger;

/**  
 * Device alias facilities method
 * @author stefano
 */
public class DeviceAliasFacilities {

	private static Logger logger = null;
	
	static{
		logger = Logger.getLogger(DeviceAliasFacilities.class);
		
	}
	
	/**
	 * Don't use
	 */
	private DeviceAliasFacilities(){
		
	}

	/**
	 * Check if the command can be digested
	 * @param notification is the command to validate
	 * @return is the the command is a valid one
	 */
	public static final boolean isCommandValid(Notification notification){
		boolean isValid = false;
		
		if(notification.getUserData() == null){
		   logger.error("Empty message received, ignored");
		   return isValid;
		}
			
		if(! (notification.getUserData() instanceof  DeviceAliasCommand) ){
		   logger.error("Unrecognized message data format: [" + notification.getUserData().getClass().getName() + "], expecte [" + DeviceAliasCommand.class.getName() + "] ignored");
		   return isValid;
		}
		
		isValid = true;
		
		return isValid;
	}
	
	/**
	 * Check if the port command can be digested
	 * @param notification is the command to validate
	 * @return is the the command is a valid one
	 */
	public static final boolean isPortCommandValid(Notification notification){
		boolean isValid = false;
		
		if(notification.getUserData() == null){
		   logger.error("Empty message received, ignored");
		   return isValid;
		}
			
		if(! (notification.getUserData() instanceof  DeviceAliasPortCommand) ){
		   logger.error("Unrecognized message data format: [" + notification.getUserData().getClass().getName() + "], expecte [" + DeviceAliasPortCommand.class.getName() + "] ignored");
		   return isValid;
		}
		
		isValid = true;
		
		return isValid;
	}

}
